package sky.cin.framework.sfoc.advanced.bootstrap;

import sky.cin.framework.network.dto.Servlet;
import sky.cin.framework.network.nio.NioServer;
import sky.cin.framework.sfoc.advanced.mvc.DispatcherServlet;
import sky.cin.framework.sfoc.core.AnnotationApplicationContext;
import sky.cin.framework.sfoc.core.common.Context;

import java.util.concurrent.ConcurrentHashMap;

public class Application {
    
    public static void run(Class<?> clazz) {
        try {
            AnnotationApplicationContext ctx = new AnnotationApplicationContext(clazz);
            ConcurrentHashMap<String, Servlet> servletMap = new ConcurrentHashMap<>();
            servletMap.put("*", new DispatcherServlet());

            Integer port = Context.getApplicationConfig().getInteger("server.port");

            new NioServer(servletMap, port).run();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
